package com.oscroll.prototype.lesson;

import com.oscroll.singleton.lesson.Seriable;

import java.io.*;

import java.util.Date;

public class WuKong extends Monkey implements Cloneable,Serializable {

    private JinGuBang jinGuBang;

    public WuKong(){
        this.setBirthday(new Date());
        this.setJinGuBang(new JinGuBang());
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }

    public Object deepClone(){
        try{
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            ObjectOutputStream oos = new ObjectOutputStream(bos);
            oos.writeObject(this);

            ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
            ObjectInputStream ois = new ObjectInputStream(bis);

            WuKong copy = (WuKong)ois.readObject();
            copy.setBirthday(new Date());

            return copy;
        }catch (Exception e){
            e.printStackTrace();
            return null;
        }
    }

    public JinGuBang getJinGuBang() {
        return jinGuBang;
    }

    public void setJinGuBang(JinGuBang jinGuBang) {
        this.jinGuBang = jinGuBang;
    }
}
